-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document huggingface_hub.get_safetensors_metadata
#417
Conversation
Co-authored-by: Mishig <[email protected]>
Co-authored-by: Mishig <[email protected]>
Thanks for the review @mishig25. I adressed all 3 comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! thanks for updating the docs !
Co-authored-by: Mishig <[email protected]>
def parse_single_file(url): | ||
# Fetch the first 8 bytes of the file | ||
headers = {'Range': 'bytes=0-7'} | ||
response = requests.get(url, headers=headers) | ||
# Interpret the bytes as a little-endian unsigned 64-bit integer | ||
length_of_header = struct.unpack('<Q', response.content)[0] | ||
# Fetch length_of_header bytes starting from the 9th byte | ||
headers = {'Range': f'bytes=8-{7 + length_of_header}'} | ||
response = requests.get(url, headers=headers) | ||
# Interpret the response as a JSON object | ||
header = response.json() | ||
return header | ||
|
||
url = "https://huggingface.co/gpt2/resolve/main/model.safetensors" | ||
header = parse_single_file(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this was still valuable to show how it actually works, no? potentially mentioning the huggingface_hub
support at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to huggingface/huggingface_hub#1855 (cc @LysandreJik @julien-c).
Since 0.20.0,
huggingface_hub
has an helper to parse safetensors metadata. This PR updates the documentation by replacing the previous "raw" snippet with this new one. The Python and JS snippets are now similar.